package com.action.boot.mongo.mongo_template.controller;

import com.action.boot.mongo.mongo_template.service.JoinService;
import com.mongodb.DBObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Wuxiang on 2017/11/12.
 * 测试 mongo  lookup 关联查询
 * 1. 初始化  http://localhost:8080/initJoin
 * 2. 拿数据  http://localhost:8080/leftJoin
 */
@RestController
public class JoinController {
    @Autowired
    JoinService joinService;

    @RequestMapping(value = "/leftJoin", method = RequestMethod.GET)
    public List<DBObject> getLeftJosin() {
        System.out.println("mongo  进行两个collectioin关联");
        return joinService.getLeftJosin();
    }

    @RequestMapping(value = "/initJoin", method = RequestMethod.GET)
    public String initJoin() {
        joinService.initLeftJoin();
        return "init两个collection成功";
    }
}
